<!-- 专业详情页 -->
<template>
	<view class="majorDetail">
		<top-page :majorList="majorList" :querySign="querySign"></top-page>
		
		<!-- 分数线 - 报录比 -->
		<view class="one_item font14">
			<view class="column_center" style="margin-bottom: 14px;">
				<text class="font18 bold">历年分数线和报录比</text>
			</view>
			<text class="semi newfs font14">
				了解近几年的初试分数线、复试分数线、实际录取分数线，有助于确定奋斗目标。\n
				了解近几年的报名人数、实际录取人数、尤其是保研人数，有助于把握竞争趋势，聪明选择，获得更大的成功概率。
			</text>
			<button @click="handleJumpOther(4)" :class="['row_center','show_btn','show_btn_2']" hover-class="hover_btn">
				<text class="fs14 white font14">查看</text>
			</button>
		</view>
		<!-- 录取名单 -->
		<view class="one_item font14">
			<view class="column_center" style="margin-bottom: 14px;">
				<text class="font18 bold">录取名单</text>
			</view>
			<text class="semi newfs font14">连续四年的实际录取名单及其成绩 </text>
			<button @click="handleJumpOther(5)" class="row_center show_btn show_btn_2" hover-class="hover_btn">
				<text class="fs14 white font14">查看</text>
			</button>
		</view>
		
		<!-- 其他事项 -->
		<view class="one_item font14">
			<view class="column_center" style="margin-bottom: 14px;">
				<text class="font18 bold">其他需要了解的事项</text>
			</view>
			<text class="semi newfs font14">研究方向、学科概况、学科培养方向；初试特殊要求、参考书；笔试、面试；导师、奖学金.... </text>
			<button @click="handleJumpOther(6)" class="row_center show_btn show_btn_2" hover-class="hover_btn">
				<text class="fs14 white font14">查看</text>
			</button>
		</view>
		<!-- 报录比详细介绍 -->
		<view class="one_item font14">
			<view class="column_center" style="margin-bottom: 14px;">
				<text class="font18 bold">报录比详细介绍</text>
			</view>
			<text class="semi newfs font14">学硕/专硕，不同研究方向、专项计划、援藏计划、单独考试、大学生退役士兵计划、少数名族骨干计划等。 </text>
			<button @click="handleJumpOther(1)" class="row_center show_btn show_btn_2" hover-class="hover_btn">
				<text class="fs14 white font14">查看</text>
			</button>
		</view>
		<!-- 调剂相关 -->
		<view class="one_item font14">
			<view class="column_center" style="margin-bottom: 14px;">
				<text class="font18 bold">调剂相关</text>
			</view>
			<text class="semi newfs font14">调剂成功的关键是信息！ </text>
			<button @click="handleJumpOther(2)" class="row_center show_btn show_btn_2" hover-class="hover_btn">
				<text class="fs14 white font14">查看</text>
			</button>
		</view>
		<!-- 其他 -->
		<view class="one_item font14">
			<view class="column_center" style="margin-bottom: 14px;">
				<text class="font18 bold">其他</text>
			</view>
			<text class="semi newfs font14">跟报录比相关的其他信息。</text>
			<button @click="handleJumpOther(3)" class="row_center show_btn show_btn_2" hover-class="hover_btn">
				<text class="fs14 white font14">查看</text>
			</button>
		</view>
		<!-- <view class="column_center" style="margin: 40rpx;">
			<text class="fs11 gray">没有更多了</text>
		</view> -->
		
		<payPopup :show="isShow" :popupsVal="popupsVal" :community="community" :jumpUrl="jumpUrl" @pageFun="handlePopStatus"></payPopup>	
		
	</view>
</template>

<script>
	import {
		getTraffic,
		forecastName,
		forecastNum,
		getMajorList,
		newarticleDetails,
		addTraffic,
		deleteTraffic,
		bulletFrame,
		ApiIsFree,
		ApiAddFree
	} from '@/api/toolbox.js'
	import payPopup from '@/pages/toolbox/components/pay-popup/pay-popup.vue'
	import topPage from "./components/top-page.vue"
	export default {
		components:{
			topPage,
			payPopup
		},
		data() {
			return {
				isShow: false,
				jumpUrl: '',
				popupsVal: '',
				community: '',
				
				isFree: false, //是否拥有免费观看次数
				//从上个页面传来的学校数据
				school_data: {
					'school': '',
					'major': '',
					'pre_reg': '',
					'all_reg': '',
					'reg_other_major': '',
					'type': ''
				},
				pre_reg_done: false, //控制【预报】按钮的样式
				show_all_news: false, //控制【院校动态】
				show_all_news_2: false,
				ratio: false, //控制【报录比】
				show_change: false, //控制【调剂】
				show_other: false, //控制【其他】
				//院校动态
				// school_news: [],
				iter: new Date().getFullYear(),
				// school_news2: {},
				resid: '',
				s_name: '',
				setclass: 'setclass',
				iStatusBarHeight: 0,
				forecastNumList: {}, //报名人数
				majorList: {}, //该专业统计
				querySign: {},	
				freeNum:0,
			}
		},
		onShow() {
			this.isShow = false;
			// this.articleDetails(1);
			// this.articleDetails(2);
			this.handleFree(this.querySign );
		},
		onLoad(options) {
			console.log('options: ',options);
			this.querySign = JSON.parse(options.items);
			let params = JSON.parse(options.items);
			this.getMajorList(params);
			this.forecastName(params);
			this.forecastNum(params);
			// this.articleDetails(1)
			// this.articleDetails(2)
			// 查询预报名状态
			// let dataP = {
			// 	'year': this.iter,
			// 	'myMajor': this.querySign.majorCode,
			// 	'myCollege': this.querySign.collegeCode
			// }
			// getTraffic(dataP).then((res)=>{
			// 	if (res.code == 100000) {
			// 		if (res.data == true) {
			// 			this.pre_reg_done = true
			// 		} else {
			// 			this.pre_reg_done = false
			// 		}
			// 	}
			// })
		},
		methods: {
			//判断是否拥有免费观看次数
			handleFree(options){
				ApiIsFree().then(res=>{
					console.log('是否免费观看，0为否',res)
					this.freeNum = res.data;
					this.isFree = false;
					if(res.data > 0){
						this.isFree = true;
					}
				})
			},
			forecastName(options) {
				//源代码查询学校信息
				if (options.collegeCode != undefined || options.collegeCode) {
					let datap = {
						"collegeCode": options.collegeCode,
						"majorCode": options.majorCode,
						'year': this.iter
					};
					forecastName(datap).then(res => {
						this.school_data = res.data;
						this.s_name = this.school_data.schoolTitleShowReturn?(this.school_data.schoolTitleShowReturn.schoolTitle + '(' + this.school_data.schoolTitleShowReturn.subjectTitle + ')'):'';
					})

				}
			},
			//获取报录比数量数据
			forecastNum(options) {
				if (options.collegeCode != undefined || options.collegeCode) {
					let datap = {
						"collegeCode": options.collegeCode,
						'majorCode': options.majorCode,
						'year': this.iter
					};
					forecastNum(datap).then(res => {
						this.forecastNumList = res.data
					})
				}
			},
			//获取专业列表
			getMajorList(options) {
				if (options.collegeCode != undefined || options.collegeCode) {
					getMajorList({
						// 'year': this.iter,
						'collegeCode': options.collegeCode,
						'majorCode': options.majorCode,
						'schoolCode': options.schoolCode,
						'pageNum': 1,
						'pageSize': 10,
						'isKwkd': true
					}).then(res => {
						if(!res.data.rows.length){
							uni.showToast({
								title: '专业列表获取失败！',
								icon: 'none'
							});
							setTimeout(()=>{
								uni.navigateBack();
							},1500)
							return;
						}
						this.majorList = res.data.rows[0]
					})
				}
			},
			goback() {
				uni.navigateBack({
					delta: 1
				})
			},
			// articleDetails(num) {
			// 	newarticleDetails({
			// 		"type": num,
			// 		"code": this.querySign.collegeCode,
			// 		// "code": this.set_collegeCode_other.collegeCode.slice(0, 14).padEnd(33, '0'),
			// 		"page": "1",
			// 		"pageSize": "10"
			// 	}).then(res => {
			// 		if (num === 1) {
			// 			console.log('888', res)
			// 			this.school_news = res.data.list
			// 		} else if (num === 2) {
			// 			console.log('999', res)
			// 			this.school_news2 = res.data.list
			// 		}

			// 	})
			// },
			
			/**
			 * 查看详情
			 * @param {Object} type 1、报录比详细介绍，2、调剂相关，3、其他，4、历年分数线和报录比，5、录取名单，6、其他需要了解事项，7、查看专业学校
			 */
			handleJumpOther(type) {
				this.jumpUrl = `/pages/toolbox/chooseMajor/major/components/other?type=${type}&collegeCode=${this.majorList.collegeCode}&majorCode=${this.majorList.majorCode}&schoolCode=${this.majorList.schoolCode}&majorList=`+JSON.stringify(this.majorList);
				if(type == 4){
					this.jumpUrl = `/pages/toolbox/chooseMajor/major/components/newbs?collegeCode=${this.majorList.collegeCode}&majorCode=${this.majorList.majorCode}&schoolCode=${this.majorList.schoolCode}&majorList=`+JSON.stringify(this.majorList);
				}
				if(type == 5){
					this.jumpUrl = `/pages/toolbox/chooseMajor/major/components/admissionList?collegeCode=${this.majorList.collegeCode}&majorCode=${this.majorList.majorCode}&schoolCode=${this.majorList.schoolCode}&majorList=`+JSON.stringify(this.majorList);
				}
				if(type == 6){
					this.jumpUrl = 	`/pages/toolbox/chooseMajor/major/components/other1?collegeCode=${this.majorList.collegeCode}&majorCode=${this.majorList.majorCode}&schoolCode=${this.majorList.schoolCode}&majorList=`+JSON.stringify(this.majorList);
				}
				if(type == 7){
					this.jumpUrl = `/pages/toolbox/chooseMajor/major/components/majorSchool?type=1&collegeCode=${this.majorList.collegeCode}&majorCode=${this.majorList.majorCode}&schoolCode=${this.majorList.schoolCode}&majorList=`+JSON.stringify(this.majorList);
				}
		
				
				if(this.isFree){
					uni.showModal({
						title: '提示',
						content: '您暂时未解锁查看专业详情功能，仅可免费试用三次，当前剩余'+this.freeNum+'次',
						cancelText: '暂不使用',
						cancelColor: '#ccc',
						confirmText: '确认使用',
						confirmColor: '#F7DD5E',
						success: (res)=> {
							if (res.confirm) {
								let params = {
									"userId": uni.getStorageSync('userId'),
								    "schoolCode": this.majorList.schoolCode,
								    "collegeCode": this.majorList.collegeCode,
								    "majorCode": this.majorList.majorCode
								}
								// 观看次数-1
								ApiAddFree(params).then(res=>{ });
								uni.navigateTo({
									url: this.jumpUrl+'&isDemo=0',
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return;
				}
				
				// 判断是否弹窗
				bulletFrame().then(res=>{
					console.log('是否弹窗支付框，capable为1则不弹窗, popup=1是社群码弹窗',res);
					if(res.data.capable == 1){
						uni.navigateTo({
							url: this.jumpUrl+'&isDemo=0',
						})
						return
					}
					//弹窗
					this.popupsVal = res.data.popup;
					this.community = res.data.community?res.data.community.community:'';
					this.isShow = true;
				})
			},
			
			handlePopStatus(status){
				console.log(111111111);
				let that = this;
				that.isShow = false;
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	.majorDetail{
		background: rgba(235, 238, 239, 0.8);
		width: 100%;
		min-height: 100vh;
		height: auto;
		padding-bottom: 20rpx;
	}
	
	.newfs {
		color: #999999;
	}
	.one_item {
		border-radius: 8rpx;
		border: 1px solid rgba(235, 238, 239, 1);
		background-color: rgba(255, 255, 255, 1);
		padding: 40rpx 30rpx;
		margin: 20rpx 32rpx;
	}
	.show_btn {
		width: 360rpx;
		height: 50px;
		line-height: 50px;
		margin: auto;
		margin-top: 24px;
		border-radius: 50px;
		background-color: #F4F4F4;
	}

	.show_btn_2 {
		width: 140rpx;
		height: 60rpx;
		line-height: 60rpx;
		background-color:  rgba(247, 221, 94, 0.8);
	}

	.show_btn_3 {
		width: 180rpx;
		height: 36px;
	}

	.hover_btn {
		background-color: #E6E6E6;
	}
	.column_center{
		text-align: center;
	}
	
	::v-deep button:after{
		border: none
	}
</style>